# -----------------------------------------------------------------------
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
# -----------------------------------------------------------------------

AC_PREREQ(2.52)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR(sctplib/programs/discard_server.c)
AM_CONFIG_HEADER(config.h)

AM_INIT_AUTOMAKE(sctplib,1.0.4)

AC_CANONICAL_HOST

dnl create only shared libtool-libraries (add --enable-shared)
dnl AC_ENABLE_SHARED(no)
dnl AM_DISABLE_SHARED

dnl set the following to yes, if you want to create static
dnl libtool-libraries, else no
dnl AC_ENABLE_STATIC(yes)

AC_ARG_ENABLE([sctp-over-udp],
[  --enable-sctp-over-udp            enable SCTP over UDP mode ],
AC_DEFINE(SCTP_OVER_UDP, 1, "Define to 1 if you want SCTP over UDP"), )

# -----------------------------------------------------------------------
# Checks for programs.
# -----------------------------------------------------------------------
AC_PROG_CC
AC_PROG_LIBTOOL

# -----------------------------------------------------------------------
# Checks for libraries.
# -----------------------------------------------------------------------

# GLib checks
# This doesn't add GLIB_CFLAGS to CFLAGS, because AM_PATH_GTK will add
# GTK_CFLAGS to CFLAGS, and GTK_CFLAGS is a superset of CFLAGS.
# However, this means that both @GLIB_LIBS@ and @GTK_LIBS@ will be
# set when generating the Makefile, so we can make programs that require
# only GLib link with @GLIB_LIBS@ and make programs that require GTK+
# link with @GTK_LIBS@ (which includes @GLIB_LIBS@).
# We don't add $GLIB_LIBS to LIBS, because we don't want to force all
# programs to be built with GLib.
#
AM_PATH_GLIB(1.2.0, CFLAGS="$CFLAGS $GLIB_CFLAGS", AC_MSG_ERROR(GLib distribution not found. On FreeBSD do: ln -s glib12-config glib-config), gmodule)

glib_LIBS="$GLIB_LIBS"
AC_SUBST(glib_LIBS)

# -----------------------------------------------------------------------
# check for curses libraries, and if found, compile some more programs
# -----------------------------------------------------------------------
#AC_CHECK_HEADERS(ncurses.h, AC_DEFINE(HAVE_NCURSES_H))
# AC_CHECK_HEADERS(curses.h, AC_DEFINE(HAVE_CURSES_H))
#AC_CHECK_LIB(ncurses, initscr, found_ncurses_lib=yes,found_ncurses_lib=no)
#if test "x$found_ncurses_lib" = "xyes" -a "x$ac_cv_header_ncurses_h" = "xyes" ; then
#	curses_LIBS="-lncurses"
#	# CPPFLAGS="$CPPFLAGS -I/usr/include/ncurses.h"
#	cursesprogs_BIN="monitor chat echo_monitor"
#else
#	cursesprogs_BIN=""
#	curses_LIBS=""
#	AC_MSG_WARN(nCurses libraries seem to be missing. Not compiling Curses-Programs!)
#fi
#AC_SUBST(cursesprogs_BIN)
#AC_SUBST(curses_LIBS)


# -----------------------------------------------------------------------
# Checks for header files.
# -----------------------------------------------------------------------
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h string.h strings.h sys/ioctl.h sys/param.h sys/socket.h sys/poll.h sys/time.h syslog.h unistd.h])
# -----------------------------------------------------------------------
# Checks for typedefs, structures, and compiler characteristics.
# -----------------------------------------------------------------------
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM

# -----------------------------------------------------------------------
# Checks for library functions.
# -----------------------------------------------------------------------
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([gettimeofday inet_ntoa memset select socket strerror strtol strtoul])

# -----------------------------------------------------------------------
# check for operating system specialities.....
# -----------------------------------------------------------------------
CFLAGS="$CFLAGS -D_REENTRANT -D_THREAD_SAFE"

case $host_os in
freebsd*)
	CFLAGS="$CFLAGS -DFreeBSD -Wall -pthread -DHAVE_SIN6_SCOPE_ID"
	thread_LIBS=""
	;;
linux*)
	case $host_cpu in
	alpha* | hppa* | i*86 | ia64* | m68* | mips* | powerpc* | sparc* | s390* | sh*)
		lt_cv_deplibs_check_method=pass_all ;;
	esac
	CFLAGS="$CFLAGS -Wall -DLINUX -DHAVE_SIN6_SCOPE_ID"
	thread_LIBS="-lpthread"
	;;
solaris*)
	CFLAGS="$CFLAGS -D__EXTENSIONS__ -Wall -DSOLARIS -D__sun -DSUN -DSUNOS_5 -D_XPG4_2"
	thread_LIBS="-lpthread"
	LDFLAGS="$LDFLAGS -lsocket -lnsl -lrt -lresolv"
	;;
darwin*)
	CFLAGS="$CFLAGS -O0 -DDARWIN -Wall -ansi -Wformat"
	thread_LIBS="-lpthread"
	;;
esac
AC_SUBST(thread_LIBS)


# -----------------------------------------------------------------------
# checks for IPv6 related stuff....
# -----------------------------------------------------------------------
AC_ARG_ENABLE(ipv6,
[  --disable-ipv6          turn off IPv6 related features and daemons])


dnl ----------
dnl IPv6 check
dnl ----------
AC_MSG_CHECKING(whether does this OS have IPv6 stack)
if test "${enable_ipv6}" = "no"; then
  AC_MSG_RESULT(disabled)
else
dnl ----------
dnl INRIA IPv6
dnl ----------
if grep IPV6_INRIA_VERSION /usr/include/netinet/in.h >/dev/null 2>&1; then
	AC_DEFINE([HAVE_IPV6], [1], [IPv6 is enabled !])
#   AC_DEFINE(INRIA_IPV6)
   LIB_IPV6=""
   AC_MSG_RESULT(INRIA IPv6)
fi
dnl ---------
dnl KAME IPv6
dnl ---------
if grep WIDE /usr/include/netinet6/in6.h >/dev/null 2>&1; then
	AC_DEFINE([HAVE_IPV6], [1], [IPv6 is enabled !])
#   AC_DEFINE(KAME)
   if test -d /usr/local/v6/lib -a -f /usr/local/v6/lib/libinet6.a; then
      LIB_IPV6="-L/usr/local/v6/lib -linet6"
   fi
   AC_MSG_RESULT(KAME)
fi

dnl ----------
dnl Linux IPv6
dnl ----------
if test "${enable_ipv6}" = "yes"; then
   AC_EGREP_CPP(yes, [
   #include <linux/version.h>
   /* 2.1.128 or later */
   #if LINUX_VERSION_CODE >= 0x020180
   yes
   #endif],
   [sctp_cv_ipv6=yes; sctp_cv_linux_ipv6=yes;AC_MSG_RESULT(Linux IPv6)])
else
   if test x`ls /proc/net/ipv6_route 2>/dev/null` = x"/proc/net/ipv6_route"
   then
      sctp_cv_ipv6=yes
      sctp_cv_linux_ipv6=yes
      AC_MSG_RESULT(Linux IPv6)
   fi
fi

if test "$sctp_cv_linux_ipv6" = "yes";then
   AC_DEFINE([HAVE_IPV6], [1], [IPv6 is enabled !])
   AC_MSG_CHECKING(for GNU libc 2.1 or higher)
   AC_EGREP_CPP(yes, [
#include <features.h>
#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1
  yes
#endif], [glibc=yes; AC_MSG_RESULT(yes)], AC_MSG_RESULT(no))
dnl   AC_DEFINE(LINUX_IPV6)
   if test "$glibc" != "yes"; then
      INCLUDES="-I/usr/inet6/include"
      if test x`ls /usr/inet6/lib/libinet6.a 2>/dev/null` != x;then
         LIB_IPV6="-L/usr/inet6/lib -linet6"
      fi
   fi
fi

dnl -----------------------
dnl Set IPv6 related values
dnl -----------------------
LIBS="$LIB_IPV6 $LIBS"
AC_SUBST(LIB_IPV6)

fi







AC_CONFIG_FILES([Makefile
                 sctplib/Makefile
                 sctplib/docs/Makefile
                 sctplib/docs/en/Makefile
                 sctplib/docs/sctplib/Makefile
                 sctplib/manual/Makefile
                 sctplib/programs/Makefile
                 sctplib/sctp/Makefile])
AC_OUTPUT
